package com.example.menulhd;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 *  ListView（右侧菜单）的适配器
 */
public class RightAdapter extends BaseAdapter {
    private Context mContext;
    private List<FoodBean> list;
    // 包含上下文，和数据list的构造方法
    public RightAdapter(Context mContext, List<FoodBean> list) {
        this.mContext = mContext;
        this.list = list;
    }
    @Override
    public int getCount() {// 数量
        return list.size();
    }

    @Override
    public Object getItem(int i) { // i位置上的数据
        return list.get(i);
    }

    @Override
    public long getItemId(int i) { // i位置的关键字
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {// i位置的视图控件

        View view1 = View.inflate(mContext, R.layout.list_item, null);

        ((TextView)view1.findViewById(R.id.tv_name)).setText(list.get(i).getName());
        ((TextView)view1.findViewById(R.id.tv_price)).setText(list.get(i).getPrice());
        ((TextView)view1.findViewById(R.id.tv_sale)).setText(list.get(i).getSales());
        ((ImageView)view1.findViewById(R.id.iv_img))
                .setBackgroundResource(list.get(i).getImg());


        return view1;
    }
}
